#!/usr/bin/env python3
import xlrd

data1 = xlrd.open_workbook(r'/home/han/zynq/zynq_pro2023/petalinux_test/doc/20230303发射天线幅相表9330_9370_9410_9450_9490.xls')
data2 = xlrd.open_workbook(r'/home/han/zynq/zynq_pro2023/petalinux_test/doc/20230303接收天线幅相表9330_9370_9410_9450_9490.xls')

cdata = [-135, -120, -105, -90, -75, -60, -45, -30, -15, 0, 15, 30, 45, 60, 75, 90, 105, 120, 135]
def import_auspic(excel):
   # print(excel.nrows)   65  表格
   if(excel.nrows != 65):
      print("幅相表错误 \n");
   
   for cnt in range(0,19):
      if(cnt != 0):
         print("  \n,{", end="")
      else:
         print("{\n {", end="")
      
      for rown in range(excel.nrows):
         if(rown == 0):
            print(str(cdata[cnt]), end=",")
         elif(rown != 64 and rown != 0):
            print(str(excel.cell_value(rown,cnt + 1)), end=",")
         else:
            print(str(excel.cell_value(rown,cnt + 1)), end="}")

   print("\n};")

def import_amplitude(excel):
   for rown in range(0, excel.nrows):
      if(rown == 0):
         print("{", end="")
      elif(rown != 64):
         print(str(excel.cell_value(rown, 1)), end=",")
      else:
         print(str(excel.cell_value(rown, 1)), end="};")
   print("\n");
if __name__ == '__main__':
   #将excel表格的内容导入到列表中
   print("#include \"common.h\"");
   print("int check_head[AB_RANDE_NUM] = {-135, -120, -105, -90, -75, -60, -45, -30, -15, 0, 15, 30, 45, 60, 75, 90, 105, 120, 135};");
   print("double T_AMPLIT[AB_CHANNEL_NUM + 1] =", end=" ")
   import_amplitude(data1.sheets()[0])
   print("double T_9330[AB_RANDE_NUM][AB_CHANNEL_NUM + 1] =")
   import_auspic(data1.sheets()[1])
   print("double T_9370[AB_RANDE_NUM][AB_CHANNEL_NUM + 1] =")
   import_auspic(data1.sheets()[2])
   print("double T_9410[AB_RANDE_NUM][AB_CHANNEL_NUM + 1] =")
   import_auspic(data1.sheets()[3])
   print("double T_9450[AB_RANDE_NUM][AB_CHANNEL_NUM + 1] =")
   import_auspic(data1.sheets()[4])
   print("double T_9490[AB_RANDE_NUM][AB_CHANNEL_NUM + 1] =")
   import_auspic(data1.sheets()[5])
   
   print("double R_AMPLIT[AB_CHANNEL_NUM + 1] =", end=" ")
   import_amplitude(data2.sheets()[0])
   print("double R_9330[AB_RANDE_NUM][AB_CHANNEL_NUM + 1] =")
   import_auspic(data2.sheets()[1])
   print("double R_9370[AB_RANDE_NUM][AB_CHANNEL_NUM + 1] =")
   import_auspic(data2.sheets()[2])
   print("double R_9410[AB_RANDE_NUM][AB_CHANNEL_NUM + 1] =")
   import_auspic(data2.sheets()[3])
   print("double R_9450[AB_RANDE_NUM][AB_CHANNEL_NUM + 1] =")
   import_auspic(data2.sheets()[4])
   print("double R_9490[AB_RANDE_NUM][AB_CHANNEL_NUM + 1] =")
   import_auspic(data2.sheets()[5])